﻿using UnityEngine;

public class PlayerUnityObject : UnityObject
{
    private Animator _animator;

    private void Start()
    {
        _animator = GetComponentInChildren<Animator>();
    }

    private void Update()
    {
        GameEntity e = _linkedEntity;
        if (e.hasTransform && e.hasVelocity)
        {
            Vector3 velocity = e.velocity.value;
            TickComponent tick = Contexts.sharedInstance.game.tick;
            float dt = tick.totalTickTime - tick.tickTime * tick.currentTick;
            Vector3 position = e.transform.position;
            Vector3 newPosition = velocity * dt + position;
            transform.position = newPosition;
            transform.forward = e.transform.forward;
            _animator.SetFloat("Speed", velocity.magnitude);
        }
    }
    
    private void OnDrawGizmos()
    {
        if (_linkedEntity.hasColliderRadius)
        {
            float radius = _linkedEntity.colliderRadius.radius;
            Gizmos.color = Color.green;
            UnityUtility.DrawCircle(transform.position, radius);
        }
    }
}